<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'普通学生列表'),
	array('op'=>'edit','title'=>'添加学生'),
	array('op'=>'fx','title'=>'分校管理'),
	array('op'=>'pk','title'=>'排课管理'),
	array('op'=>'xs','title'=>'学生管理'),
	array('op'=>'qd','title'=>'签到管理'),
	array('op'=>'pj','title'=>'评价管理'),	
);

if($_RQ['op']=='fx'){

 
	exi('','','jy_kexie/store.index/','');

}
if($_RQ['op']=='pk'){

	 
	exi('','','jy_kexie/store.lesson_pai/','');

	
}
if($_RQ['op']=='xs'){

	
	exi('','','jy_kexie/store.user/','');


}
if($_RQ['op']=='qd'){

	
	exi('','','jy_kexie/store.sign//type=0','');


}
if($_RQ['op']=='pj'){

	exi('','','jy_kexie/store.comment//type=0','');

}
if($_RQ['op']=='list'){
	$params=array('storeid'=>$this->store_id);
	$params['uniacid']=$_SESSION['uniacid'];
	$params['status']=0;
	$params['isvip']=0;
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	if(!empty($_RQ['area_id'])){
		$params['area_id']=intval($_RQ['area_id']);
		$return['params']['area_id']=$_RQ['area_id'];
	}
	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_kexie_user',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
				$member=model('core/member')->detail($item['mid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
				$item['member']=$member;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('total'=>$total,'data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			//array('name'=>'area_id','title'=>'所属区域','type'=>'select','options'=>'areas'),
			//array('type'=>'select','name'=>'storeid','title'=>'所属学校','options'=>'stores'),
			array('name'=>'name','title'=>'学生姓名','type'=>'string'),
			array('name'=>'username','title'=>'学生账号','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),
			array('name'=>'member','title'=>'粉丝信息','type'=>'member'),
			array('name'=>'status','title'=>'是否拉黑','type'=>'switch','set'=>'set'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'name','width'=>15,'title'=>'学生姓名','type'=>'string'),
		)
	);
	$return['areas']=pdo_getall('jy_kexie_area',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['stores']=pdo_getall('jy_kexie_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_kexie_user',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('name'=>'name','title'=>'学生姓名','type'=>'string'),
					array('name'=>'mobile','title'=>'手机号','type'=>'string'),
					array('name'=>'username','title'=>'学生账号','type'=>'string'),
					array('name'=>'password','title'=>'密码','type'=>'password'),
					//array('name'=>'area_id','title'=>'所属区域','type'=>'select2','options'=>'areas',
					//	'name2'=>'storeid','title2'=>'所属学校','options2'=>'stores'
					//),
				)
			),
		)
	);
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$return['areas']=pdo_getall('jy_kexie_area',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	foreach($return['areas'] as &$sv){
		$sv['stores']=pdo_getall('jy_kexie_store',array('area_id'=>$sv['id'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['name']){
		exi('请填写学生姓名','error');
	}
	if(!$postdata['storeid']){
		//exi('请选择学校','error');
	}
	//$postdata['time']=ijson_encode($postdata['time']);	
	$data=array_fields(array('name','username','password','mobile'),$postdata);
	$id=intval($postdata['id']);	
	if($id){
		pdo_update('jy_kexie_user',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$store=pdo_get('jy_kexie_store',array('id'=>$this->store_id,'uniacid'=>$_SESSION['uniacid']));
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		$data['storeid']=$this->store_id;
		$data['area_id']=$store['area_id'];
		pdo_insert('jy_kexie_user',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_kexie_user',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的学生！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_kexie_user',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}